package com.lqg.bookLibrary.common.core.domain;

import com.lqg.bookLibrary.pojo.Users;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


public class LoginUser implements UserDetails {
    private static final long serialVersionUID = 1L;
    private Users user;
    //private Long userId;
    /**
     * 权限列表
     */
    private List<String> permissions;
    /**
     * 权限集合
     * */
    private Collection<? extends GrantedAuthority> authorities;

    public LoginUser(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        this.user = new Users(username,password);
        this.authorities=authorities;
    }

//    public LoginUser(Long uid, User user, List<String> permissions)
//    {
//        this.userId = uid;
//        this.user = user;
//        this.permissions = permissions;
//    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

//    public Long getUserId() {
//        return userId;
//    }

//    public void setUserId(Long userId) {
//        this.userId = userId;
//    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }


    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getEmail();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String toString() {
        return "LoginUser{" +
                "user=" + user.toString() +
                ", permissions=" + permissions +
                ", authorities=" + authorities +
                '}';
    }
}
